<?php
// +----------------------------------------------------------------------
// | author: thinkphp
// +----------------------------------------------------------------------

namespace app\api\lists\order;

use app\api\lists\BaseApiDataLists;
use app\common\lists\ListsSearchInterface;
use app\common\model\order\Order;

/**
 * 列表
 * Class OrderLists
 * @package app\api\lists\line
 */
class OrderLists extends BaseApiDataLists implements ListsSearchInterface
{

    /**
     * @notes 搜索条件
     * @return \string[][]
     */
    public function setSearch(): array
    {
        return [
            '=' => ['order_no']
        ];
    }


    /**
     * @notes 自定查询条件
     * @return array
     */
    public function queryWhere()
    {
        $where[] = ['id', '>', 0];
        $where[] = ['user_id', '=', $this->userId];
        if (!empty($this->params['keyword'])) {
            $where[] = ['order_no', 'like', '%' . $this->params['keyword'] . '%'];
            $where[] = ['people_name', 'like', '%' . $this->params['keyword'] . '%'];
            $where[] = ['people_phone', 'like', '%' . $this->params['keyword'] . '%'];
        }
        if (!empty($this->params['status'])) {
            $where[] = ['order_status', '=', $this->params['status']];
        }
        return $where;
    }


    /**
     * @notes 获取列表
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function lists(): array
    {
//        if (!empty($this->params['keyword'])) {
//            $where[] = ['order_no', 'like', '%' . $this->params['keyword'] . '%'];
//            $where[] = ['people_name', 'like', '%' . $this->params['keyword'] . '%'];
//            $where[] = ['people_phone', 'like', '%' . $this->params['keyword'] . '%'];
//        }
//
//        if (!empty($this->params['status'])) {
//            $where[] = ['status', '=', $this->params['status']];
//        }

        // 查询最近一天的价格记录
        $result = Order::where($this->queryWhere())
            ->where($this->searchWhere)
            ->limit($this->limitOffset, $this->limitLength)
            ->select()
            ->toArray();
        return $result;
    }


    /**
     * @notes 获取数量
     * @return int
     */
    public function count(): int
    {
        return Order::
        where($this->searchWhere)
            ->where($this->queryWhere())
            ->count();
    }
}